package com.mcxx.common;

import com.google.common.io.Files;
import org.apache.commons.io.Charsets;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.List;

public class ExternalFileUtil {

    private final static org.slf4j.Logger logger = LoggerFactory.getLogger(ExternalFileUtil.class);

    public static Boolean traverseFolder(String path,String word) throws IOException {
        try{
            File file = new File(path);
            if (file.exists()) {

                List<String> strings = Files.readLines(file, Charsets.UTF_8);
                if (null == strings || strings.size() == 0) {

                    return false;
                } else {
                    for (String string : strings) {

                        if (string.contains(word)) {

                            return true;
                        }
                    }
                    return false;
                }
            } else {
                file.createNewFile();
                logger.info("文件不存在!");
                return false;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }


    public static void writeLog(String classPath, String methodName){
        try{
            BufferedWriter out = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(classPath,true)));
            out.write(methodName+"");
            out.newLine();
            out.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
